//
//  SuperViewController.m
//  TaxDealPlatform
//
//  Created by Zhengtong on 15/4/29.
//  Copyright (c) 2015年 Zhengtong. All rights reserved.
//

#import "SuperViewController.h"

@interface SuperViewController ()<MBProgressHUDDelegate>
{
    UITapGestureRecognizer *_taptohideGesture;
    UIView *statusView ;
    MBProgressHUD *HUD;
}


@end

@implementation SuperViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
}

#pragma mark - 提示 -成功状态
- (void)success:(NSString *)msg
{
    MBProgressHUD *hud = [MBProgressHUD HUDForView:self.view];
    if (hud)
    {
        hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];
        hud.mode = MBProgressHUDModeCustomView;
        hud.labelText = msg;
        [hud hide:YES afterDelay:1.0];
    }
    self.MBhud = hud ;

}
//等待状态
- (void)showActivite:(NSString *)msg
{
    [self.MBhud removeFromSuperview];
    self.MBhud = nil ;
    MBProgressHUD *hud;
    if (self.navigationController.view != nil)
    {
        hud = [MBProgressHUD HUDForView:self.navigationController.view];
        
    }else
    {
        hud = [MBProgressHUD HUDForView:self.view];
        
    }
    
    if (!hud)
    {
        hud = [[MBProgressHUD alloc] initWithView:self.view];
    }
    hud.opaque = YES;
    hud.dimBackground = YES;
    hud.square = YES;
    hud.removeFromSuperViewOnHide = TRUE;
    if (self.navigationController.view!=nil)
    {
        [self.navigationController.view addSubview:hud];
        
    }else
    {
        [self.view addSubview:hud];
        
    }
    [hud setLabelText:msg];
    [hud show:YES];
    self.MBhud = hud ;
}
- (void)showHUD:(NSString *)msg
{
    [self.MBhud removeFromSuperview];
    self.MBhud = nil ;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.removeFromSuperViewOnHide = TRUE;
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabelText = msg ;
    hud.detailsLabelFont = [UIFont boldSystemFontOfSize:14];
    [hud show:YES];
    [hud hide:YES afterDelay:1.5f];
    self.MBhud = hud ;
    
}

//方式1.直接在View上show
- (void)myShowHUD:(NSString *)msg
{
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

HUD.delegate = self;



//常用的设置

//小矩形的背景色

HUD.color = [UIColor clearColor];//这儿表示无背景

//显示的文字

    HUD.labelText = msg;

//细节文字

    HUD.detailsLabelText = msg;

//是否有庶罩

HUD.dimBackground = YES;

[HUD hide:YES afterDelay:2];



//只显示文字

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

hud.mode = MBProgressHUDModeText;

    hud.labelText = msg;

hud.margin = 10.f;

hud.yOffset = 150.f;

hud.removeFromSuperViewOnHide = YES;

[hud hide:YES afterDelay:3];
    
    
    
}
- (void)showProgress:(double)progress
{
    [self.MBhud removeFromSuperview];
    self.MBhud = nil ;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeDeterminateHorizontalBar;
    hud.removeFromSuperViewOnHide = TRUE;
    hud.progress = progress;
    hud.labelText = [NSString stringWithFormat:@"下载中%0.2f%%",progress*100];
    [hud show:YES];
    [hud hide:YES afterDelay:1.5f];
    self.MBhud = hud ;
}

- (void)showAnimationaIndicator:(NSString *)msg
{
    [self.indicator removeFromSuperview];
    self.indicator = nil;
 
    ZTAnimationIndicator*  indicator = [[ZTAnimationIndicator alloc]initWithFrame:CGRectMake((self.navigationController.view.width- 80)*0.5, (self.navigationController.view.height- 80)*0.5-50, 80, 80)];
    [indicator setLoadText:msg];
    [self.view addSubview:indicator];
    self.indicator = indicator;
}
- (void)showAnimationaIndicator:(NSString *)msg withFrame:(CGRect)frame
{
    [self.indicator removeFromSuperview];
    self.indicator = nil;
    
    ZTAnimationIndicator*  indicator = [[ZTAnimationIndicator alloc]initWithFrame:frame];
    [indicator setLoadText:msg];
    [self.view addSubview:indicator];
    self.indicator = indicator;
}

//通用弹窗
- (void)alentView:(NSString *)title message:(NSString *)message cancelTitle:(NSString *)cancelTitle confirmTitle:(NSString *)confirmTitle{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:confirmTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
    }];
    
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];
    
}






- (void)phoneAlentView:(UserInfoModel *)model{
    
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:model.name message:model.phone preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
//    打完电话后可以回到之前界面
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",model.phone];
        //            NSLog(@"str======%@",str);
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }];

    
}

- (void)mobileAlentView:(UserInfoModel *)model{
    
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"请选择操作" preferredStyle:UIAlertControllerStyleAlert];
   
     UIAlertAction *phoneAction = [UIAlertAction actionWithTitle:@"电话" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        //    打完电话后可以回到之前界面
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",model.phone];
        //            NSLog(@"str======%@",str);
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }];

    UIAlertAction *SMSAction = [UIAlertAction actionWithTitle:@"短信" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
       
        
    }];
    
    
}


//---点击人员详情列表手机号码的弹框---

//func mobileAlentView(user:User){
//    
//    
//    let alertController = UIAlertController(title: "提示",
//                                            message: "请选择操作", preferredStyle: .Alert)
//    
//    let phoneAction = UIAlertAction(title: "电话", style: .Default,
//                                    handler: {
//                                        action in
//                                        //print("点击了确定")
//                                        //可以在此处进行跳转
//                                        
//                                        let phone = "tel://" + user.mobile
//                                        UIApplication.sharedApplication().openURL(NSURL(string:phone)!)
//                                        
//                                        
//                                    })
//    
//    let SMSAction = UIAlertAction(title: "短信", style: .Default,
//                                  handler: {
//                                      action in
//                                      if MFMessageComposeViewController.canSendText(){
//                                          let controller = MFMessageComposeViewController()
//                                          //设置短信内容
//                                          controller.body = "短信内容：欢迎来到hangge.com"
//                                          //设置收件人列表
//                                          controller.recipients = [user.mail]
//                                          //设置代理
//                                          //                                            controller.messageComposeDelegate = self
//                                          //打开界面
//                                          self.presentViewController(controller, animated: true, completion: { () -> Void in
//                                              
//                                          })
//                                      }else{
//                                          print("本设备不能发送短信")
//                                      }
//                                      
//                                  })
//    
//    alertController.addAction(phoneAction)
//    alertController.addAction(SMSAction)
//    self.presentViewController(alertController, animated: true, completion: nil)
//    
//}
//
//
//}















#pragma mark - 键盘事件 -
- (void)addKeyBoardNotification
{
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(keyboardWillShow:)
     name:UIKeyboardWillShowNotification
     object:nil];
    
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(keyboardWillHide:)
     name:UIKeyboardWillHideNotification
     object:nil];
    
}
#pragma mark - 键盘时间处理 -
- (void)keyboardWillShow:(NSNotification *) notification
{
    // 获取键盘高度
    [self.view removeGestureRecognizer:_taptohideGesture];
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
    tap.cancelsTouchesInView = YES;
    _taptohideGesture = tap;
    [self.view addGestureRecognizer:tap];
}
- (void)keyBoarHide
{
    
}
- (void)keyboardWillHide:(NSNotification *) notification

{
    for (UITapGestureRecognizer *tap in self.view.gestureRecognizers)
    {
        
        if ([tap isEqual:_taptohideGesture])
            
        {
            [self keyBoarHide];
            [self.view removeGestureRecognizer:tap];
        }
    }
}
- (void)hideKeyboard:(UITapGestureRecognizer *)tap

{
    if ([tap isEqual:_taptohideGesture])
        
    {
        [self keyBoarHide];
        [self.view removeGestureRecognizer:tap];
    }
}

-(void)removeNotification
{
    [[NSNotificationCenter defaultCenter]
     removeObserver:self
     name:UIKeyboardWillShowNotification
     object:nil];
    
    [[NSNotificationCenter defaultCenter]
     removeObserver:self
     name:UIKeyboardWillHideNotification
     object:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
